﻿using NJabber.Stream.Elements;
using NUnit.Framework;

namespace NJabber.Client.StanzaFactories
{
    [TestFixture]
    public class SubscriptionStanzaFactoryTest
    {
        private JID receiverId = "receiver@jid.com";

        private SubscriptionStanzaFactory factory;

        [SetUp]
        public void TestSetup()
        {
            factory = new SubscriptionStanzaFactory();
        }

        [Test]
        public void CreateSubscribeRequest_CreatesCorrectStanza()
        {
            PresenceStanza stanza = (PresenceStanza)factory.CreateSubscribeRequest(receiverId);

            VerifySubscritionStanza(stanza, PresenceStanzaType.Subscribe);
        }

        [Test]
        public void CreateSubscriptionApproveResponse_CreatesCorrectStanza()
        {
            PresenceStanza stanza = (PresenceStanza) factory.CreateSubscriptionApproveResponse(receiverId);

            VerifySubscritionStanza(stanza, PresenceStanzaType.Subscribed);
        }

        [Test]
        public void CreateSubscriptionDenyResponse_CreatesCorrectStanza()
        {
            PresenceStanza stanza = (PresenceStanza) factory.CreateSubscriptionDenyResponse(receiverId);

            VerifySubscritionStanza(stanza, PresenceStanzaType.Unsubscribed);
        }

        [Test]
        public void CreateSubscriptionCancellationRequest_CreatesCorrectStanza()
        {
            PresenceStanza stanza = (PresenceStanza) factory.CreateSubscriptionCancellationRequest(receiverId);

            VerifySubscritionStanza(stanza, PresenceStanzaType.Unsubscribed);
        }

        [Test]
        public void CreateUnsubscribeRequest_CreatesCorrectStanza()
        {
            PresenceStanza stanza = (PresenceStanza) factory.CreateUnsubscribeRequest(receiverId);

            VerifySubscritionStanza(stanza, PresenceStanzaType.Unsubscribe);
        }

        private void VerifySubscritionStanza(PresenceStanza stanza, string stanzaType)
        {
            Assert.That(stanza.Type, Is.EqualTo(stanzaType));
            Assert.That(stanza.To, Is.EqualTo(receiverId));
        }
    }
}
